﻿using GalaSoft.MvvmLight;

namespace MoreEPG.ViewModel
{
   
    public class SettingsViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the SettingsViewModel class.
        /// </summary>
        public SettingsViewModel()
        {
            this.AutoHD = Properties.Settings.Default.AutoHD;
            this.CFSuffix = Properties.Settings.Default.CFSuffix;
            this.FSKInfo = Properties.Settings.Default.FSKInfo;
            this.LoadImg = Properties.Settings.Default.LoadImg;
            this.LoadLogo = Properties.Settings.Default.LoadLogo;
            this.LoadMC = Properties.Settings.Default.LoadEPG;
            this.Reindex = Properties.Settings.Default.Reindex;
            this.UpdateDB = Properties.Settings.Default.UpdateDB;
        }


        /// <summary>
        /// The <see cref="UpdateDB" /> property's name.
        /// </summary>
        public const string UpdateDBPropertyName = "UpdateDB";

        private bool? _UpdateDB = false;

        /// <summary>
        /// Gets the UpdateDB property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? UpdateDB
        {
            get
            {
                return _UpdateDB;
            }

            set
            {
                if (_UpdateDB == value)
                {
                    return;
                }

                _UpdateDB = value;

                if (Properties.Settings.Default.UpdateDB != (bool)_UpdateDB)
                {
                    Properties.Settings.Default.UpdateDB = (bool)_UpdateDB;
                    Properties.Settings.Default.Save();
                }
                
                
                // Update bindings, no broadcast
                RaisePropertyChanged(UpdateDBPropertyName);

            }
        }

        /// <summary>
        /// The <see cref="LoadMC" /> property's name.
        /// </summary>
        public const string LoadMCPropertyName = "LoadMC";

        private bool? _LoadMC = false;

        /// <summary>
        /// Gets the LoadMC property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? LoadMC
        {
            get
            {
                return _LoadMC;
            }

            set
            {
                if (_LoadMC == value)
                {
                    return;
                }

                
                _LoadMC = value;

                if (Properties.Settings.Default.LoadEPG != (bool)_LoadMC)
                {
                    Properties.Settings.Default.LoadEPG = (bool)_LoadMC;
                    Properties.Settings.Default.Save();
                }
                // Update bindings, no broadcast
                RaisePropertyChanged(LoadMCPropertyName);

               
            }
        }

        /// <summary>
        /// The <see cref="AutoHD" /> property's name.
        /// </summary>
        public const string AutoHDPropertyName = "AutoHD";

        private bool? _AutoHD = false;

        /// <summary>
        /// Gets the AutoHD property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? AutoHD
        {
            get
            {
                return _AutoHD;
            }

            set
            {
                if (_AutoHD == value)
                {
                    return;
                }

                
                _AutoHD = value;

                if (Properties.Settings.Default.AutoHD != (bool)_AutoHD)
                {
                    Properties.Settings.Default.AutoHD = (bool)_AutoHD;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(AutoHDPropertyName);

            }
        }


        /// <summary>
        /// The <see cref="LoadImg" /> property's name.
        /// </summary>
        public const string LoadImgPropertyName = "LoadImg";

        private bool? _LoadImg = false;

        /// <summary>
        /// Gets the LoadImg property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? LoadImg
        {
            get
            {
                return _LoadImg;
            }

            set
            {
                if (_LoadImg == value)
                {
                    return;
                }

                
                _LoadImg = value;

                if (Properties.Settings.Default.LoadImg != (bool)_LoadImg)
                {
                    Properties.Settings.Default.LoadImg = (bool)_LoadImg;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(LoadImgPropertyName);

               
            }
        }

        /// <summary>
        /// The <see cref="LoadLogo" /> property's name.
        /// </summary>
        public const string LoadLogoPropertyName = "LoadLogo";

        private bool? _LoadLogo = false;

        /// <summary>
        /// Gets the LoadLogo property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? LoadLogo
        {
            get
            {
                return _LoadLogo;
            }

            set
            {
                if (_LoadLogo == value)
                {
                    return;
                }

                
                _LoadLogo = value;

                if (Properties.Settings.Default.LoadLogo != (bool)_LoadLogo)
                {
                    Properties.Settings.Default.LoadLogo = (bool)_LoadLogo;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(LoadLogoPropertyName);

                
            }
        }

        /// <summary>
        /// The <see cref="Reindex" /> property's name.
        /// </summary>
        public const string ReindexPropertyName = "Reindex";

        private bool? _Reindex = false;

        /// <summary>
        /// Gets the Reindex property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? Reindex
        {
            get
            {
                return _Reindex;
            }

            set
            {
                if (_Reindex == value)
                {
                    return;
                }

               
                _Reindex = value;

                if (Properties.Settings.Default.Reindex != (bool)_Reindex)
                {
                    Properties.Settings.Default.Reindex = (bool)_Reindex;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(ReindexPropertyName);

            }
        }

        /// <summary>
        /// The <see cref="CFSuffix" /> property's name.
        /// </summary>
        public const string CFSuffixPropertyName = "CFSuffix";

        private bool? _CFSuffix = false;

        /// <summary>
        /// Gets the CFSuffix property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? CFSuffix
        {
            get
            {
                return _CFSuffix;
            }

            set
            {
                if (_CFSuffix == value)
                {
                    return;
                }

                
                _CFSuffix = value;

                if (Properties.Settings.Default.CFSuffix != (bool)_CFSuffix)
                {
                    Properties.Settings.Default.CFSuffix = (bool)_CFSuffix;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(CFSuffixPropertyName);

                
            }
        }

        /// <summary>
        /// The <see cref="FSKInfo" /> property's name.
        /// </summary>
        public const string FSKInfoPropertyName = "FSKInfo";

        private bool? _FSKInfo = false;

        /// <summary>
        /// Gets the FSKInfo property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool? FSKInfo
        {
            get
            {
                return _FSKInfo;
            }

            set
            {
                if (_FSKInfo == value)
                {
                    return;
                }

                
                _FSKInfo = value;

                if (Properties.Settings.Default.FSKInfo != (bool)_FSKInfo)
                {
                    Properties.Settings.Default.FSKInfo = (bool)_FSKInfo;
                    Properties.Settings.Default.Save();
                }

                // Update bindings, no broadcast
                RaisePropertyChanged(FSKInfoPropertyName);

            }
        }
    }
}